	var img_server =$("#imgserver").val();
	var picArr = [];
	var videoArr = [];
	var picAddress = $("#picAddress").val();
	if(picAddress){
		if(picAddress.indexOf(",")!=-1){
			picArr = picAddress.split(",");
		}else{
			picArr.push(picAddress);
		}
	}
	var videoAddress =  $("#videoAddress").val();
	if(videoAddress){
		if(videoAddress.indexOf(",")!=-1){
			videoArr =videoAddress.split(","); 
		}else{
			videoArr.push(videoAddress);
		}
	}
	function deleteImg(obj){
		layer.confirm('是否执行此操作？', {
			icon : 3,
			btn : [ '确认', '取消' ]
		}, function(index) {
			layer.close(index);
			var picPath = $(obj).prev("img").attr("data-path");
			var index = picArr.indexOf(picPath);
			if(index>-1){
				 $(obj).parent("li").remove();
				 picArr.splice(index, 1);
			}
			if(picArr.length == 0){
				$("<img  src='/resources/images/noimage.gif' style='width:33.3%;height:200px;'/>").appendTo($("#picUL"));
			} 
		},
		function(index){
			layer.close(index);
		});
		
	}
	
	function deleteVideoPath(obj){
		layer.confirm('是否执行此操作？', {
			icon : 3,
			btn : [ '确认', '取消' ]
		}, function(index) {
			layer.close(index);
			var filePath = $(obj).prev("a").attr("data-path");
			var index = videoArr.indexOf(filePath);
			if(index>-1){
				 $(obj).parent("li").remove();
				 videoArr.splice(index, 1);
			}
			if(videoArr.length == 0){
				$("<img  src='/resources/images/novideo.png' style='width:33.3%;height:200px;'/>").appendTo($("#videoUL"));
			} 
		},
		function(index){
			layer.close(index);
		});
	}
	$(function(){
		$('img').viewer();
		$("#leader-tree").tree({
			url:'/video/plan/log/getLeaderTree',
			checkbox:function(node){
				if(node.leaf){
					return true;
				}else{
					return false;
				}
			},
			onSelect: function (node) {
                var cknodes = $('#leader-tree').tree("getChecked");
                for (var i = 0; i < cknodes.length; i++) {
                    if (cknodes[i].id != node.id) {
                        $('#leader-tree').tree("uncheck", cknodes[i].target);
                    }
                }
                if (node.checked) {
                    $('#leader-tree').tree('uncheck', node.target);

                } else {
                    $('#leader-tree').tree('check', node.target);

                }

            },
            onLoadSuccess: function (node, data) {
                $(this).find('span.tree-checkbox').unbind().click(function () {
                    $('#leader-tree').tree('select', $(this).parent());
                    return false;
                });
            }
		});
		
	}); 

function save(obj){
	var $form = $(obj).parents("form");
	var $url = $form.attr("action");
	if (!$form.form("validate")) {// 验证没通过，返回
		return false;
	}
	var s_leadId = $("#leader-tree").tree("getChecked");
	var leadId =0;
	if(s_leadId && s_leadId.length>0){
		 leadId = s_leadId[0].id.substring(s_leadId[0].id.indexOf("_")+1);
	}
	golbal.progress();
	$form.ajaxSubmit({
		url :$url, 
		type:"POST",
		data:{"picAddress":picArr.join(","),"videoAddress":videoArr.join(","),"leaderId":leadId},
		success : function(msg) {
			$.messager.progress("close");
			if (msg.success == 1) {
				layer.alert(msg.msg || "添加成功！", {
					icon : 1,
					skin : "layer-ext-moon",
				}, function(index) {
					layer.close(index);
					closeDialog(obj);
					$("#planResource-datagrid").datagrid("reload");
				});
			} else {
				layer.alert("添加失败！请稍候重试：" + (msg.msg || ""), {
					icon : 2,
					skin : "layer-ext-moon",
				}, function(index) {
					layer.close(index);
					window.close()
					if (msg.o != undefined && $backUrl) {
						window.location.href = $backUrl;
					}
				});
			}
		}
	 });
	return false;
}